<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>${project_name}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${base}/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${base}/static/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${base}/static/layuiadmin/style/login.css" media="all">
    <script src="${base}/static/js/jsbn.js"></script>
    <script src="${base}/static/js/prng4.js"></script>
    <script src="${base}/static/js/rng.js"></script>
    <script src="${base}/static/js/rsa.js"></script>
    <script src="${base}/static/js/base64.js"></script>
</head>
<body>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>${project_name}</h2>
        </div>
        <form class="layadmin-user-login-box layadmin-user-login-body layui-form" method="post" action="${base}/login">
            <input type="hidden" id="LAY-user-login-enPassword" name="enPassword"/>
            <input type="hidden" id="LAY-user-login-modulus" value="${modulus}"/>
            <input type="hidden" id="LAY-user-login-exponent" value="${exponent}"/>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                       for="LAY-user-login-username"></label>
                <input type="text" name="username" id="LAY-user-login-username" lay-verify="required"
                       placeholder="用户名"
                       value=""
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-password"></label>
                <input type="password" id="LAY-user-login-password" lay-verify="required"
                       placeholder="密码" autocomplete="new-password" value="" class="layui-input">
            </div>
            <div class="layui-form-item" style="margin-bottom: 20px;">
                <input type="checkbox" id="isRememberUsername" name="remember" lay-skin="primary" title="记住用户名">
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登&nbsp;录
                </button>
            </div>
        </form>
        <div class="layui-trans layadmin-user-login-footer">
        [#--<p>©2018 物流联盟 沪ICP备18015814号</p>--]
        </div>
    </div>

</div>

<script src="${base}/static/layuiadmin/layui/layui.js"></script>
<script>
    var USER_KEY = 'memberUsername';

    layui.config({
        base: '${base}/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'user'], function () {
        var $ = layui.$,
                setter = layui.setter,
                layer = layui.layer,
                form = layui.form;

        [#if message?has_content]
            layer.msg('${message}', {icon: 2});
        [/#if]

        var username = layui.data(setter.tableName)[USER_KEY];
        // 记住用户名
        if (username) {
            $("#isRememberUsername").prop("checked", true);
            $("#LAY-user-login-username").val(username);
            $("#LAY-user-login-password").focus();
        } else {
            $("#isRememberUsername").prop("checked", false);
            $("#LAY-user-login-username").focus();
        }

        form.render();

        form.on('submit(LAY-user-login-submit)', function (data) {

            if (data.field.remember === 'on') {
                layui.data(setter.tableName, {
                    key: USER_KEY
                    , value: data.field.username
                });
            } else {
                layui.data(setter.tableName, {
                    key: USER_KEY
                    , value: ''
                });
            }

            var rsaKey = new RSAKey();
            rsaKey.setPublic(b64tohex($('#LAY-user-login-modulus').val()), b64tohex($('#LAY-user-login-exponent').val()));
            var enPassword = hex2b64(rsaKey.encrypt($("#LAY-user-login-password").val()));
            console.log("密码" + enPassword);
            $('[name=enPassword]').val(enPassword);
            return true;
        });
    })
    ;
</script>
</body>
</html>